﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnglishLibrary;
using Global;
using DataTransfer;

namespace Display
{
    public partial class RateUC : UserControl
    {
        RateDT rateDT = new RateDT();

        //delegate function
        public delegate void SelectedIndexChanged(string selectedValue);
        //delegate object
        public SelectedIndexChanged ChangeRate;

        public RateUC()
        {
            InitializeComponent();
        }

        private void RateUC_Load(object sender, EventArgs e)
        {
            List<Rate> rates = rateDT.GetListRate();
            this.cbRate.DataSource = rates;
            this.cbRate.DisplayMember = Constant.RATEFIELD.RATETEXT;
            this.cbRate.ValueMember = Constant.RATEFIELD.RATEID;
            this.cbRate.SelectedIndex = Default.SETTINGS.DEFAULT_RATE;
        }

        private void RateUC_Resize(object sender, EventArgs e)
        {
            this.cbRate.Size = new Size(this.Width, this.Height);
        }

        #region Usercontrol Properties
        public string SelectedValue
        {
            get
            {
                return this.cbRate.SelectedValue.ToString();
            }
            set
            {
                this.cbRate.SelectedValue = value;
            }
        }

        public int SelectedIndex
        {
            get
            {
                return this.cbRate.SelectedIndex;
            }
            set
            {
                if (this.cbRate != null)
                    this.cbRate.SelectedIndex = value;
            }
        }
        #endregion

        private void cbRate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ChangeRate != null)
                ChangeRate(this.SelectedValue);
        }

        private void RateUC_MouseEnter(object sender, EventArgs e)
        {
            //((TestReminder)this.Parent).MouseEnter();
        }

        private void RateUC_MouseLeave(object sender, EventArgs e)
        {
            //((TestReminder)this.Parent).MouseLeave();
        }

        private void cbRate_MouseEnter(object sender, EventArgs e)
        {
            //((TestReminder)this.Parent.Parent).MouseEnter();
        }

        private void cbRate_MouseLeave(object sender, EventArgs e)
        {
            //((TestReminder)this.Parent.Parent).MouseLeave();
        }
    }
}
